package com.wyh.controller;

import cn.hutool.core.bean.BeanUtil;
import com.wyh.bean.User;
import com.wyh.common.bean.PageBean;
import com.wyh.common.bean.ResultBean;
import com.wyh.common.controller.BaseController;
import com.wyh.common.group.ISave;
import com.wyh.common.group.V;
import com.wyh.query.UserQuery;
import com.wyh.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@Api(tags = "用户管理")
public class UserController extends BaseController {

    @Autowired
    UserService userService;

    @ApiOperation("查询用户信息")
    @GetMapping("/user")
    public ResultBean get(int id){
        User user = userService.get(id);
        return success("客户信息",user);
    }
    @ApiOperation("保存用户信息")
@PostMapping("/user")
    public ResultBean save(@Validated(ISave.class) @RequestBody User user, BindingResult result){

        V.validate(result);
        return success("保存成功");
    }

    @ApiOperation("查询用户列表")
    @PostMapping("/user/list")
    public ResultBean query(@RequestBody UserQuery query){
       // PageBean pageBean = userService.query(user);
        PageBean bean=userService.queryByMap(BeanUtil.beanToMap(query));
        return success("客户列表",bean);
    }

}
